package com.example.printservice.controller;


import com.example.printservice.Service.MyPrintService;
import com.example.printservice.Service.TokenService;
import com.example.printservice.constants.Constants;
import com.example.printservice.entity.DocumentConfiguration;
import com.example.printservice.entity.TonkeEntity;
import com.example.printservice.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.parser.Token;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.UUID;

@RestController
@Slf4j

@Api(tags = "")
public class PrintController {

    @Resource
    MyPrintService myPrintService;

    @Autowired
    private TokenService tokenService;

    @PostMapping("/print")
    @ApiOperation(value = "打印")
    public R print(@Valid @RequestBody DocumentConfiguration documentConfiguration /*, BindingResult result*/) {

        TonkeEntity byId = tokenService.getById(1); //数据库查询数据
        String token = documentConfiguration.getToken(); //获取传递回来的数据
        if((token+byId.getToken()).equals(byId.getAlltoken())&&byId.getStatus()==1) //判断token是否相等
        {
            System.out.println(documentConfiguration);
            myPrintService.print(documentConfiguration); //进行打印
            tokenService.deleteById(byId.getId());  //打印之后删除数据库数据
        }else {
            return R.error("别试了");
        }





        return R.ok();
    }

}
